<?php
declare (strict_types=1);

namespace app\ypz_forum\controller;

use app\BaseController;
use think\facade\Db;
use think\facade\Session;

class Index extends BaseController
{
    //登录逻辑 R2103010231
    public function login()
    {
        return view();
    }
    
    //登录逻辑 R2103010231
    public function doLogin()
    {
        $username = $this->request->post('username');
        $password = $this->request->post('password');
        if (!$username) {
            $this->error('请输入用户名!');
        }
    
        if (!$password) {
            $this->error('请输入密码!');
        }
    
        $res = Db::name('user')
            ->where('username', $username)
            ->find();
    
        if ($res) {
            
            if ($res['status'] == 1) {
                $this->error('你的账号被禁止登录,请联系管理员');
            }
    
            if ($res['status'] == 2) {
                $this->error('你的账号已被禁止发言,请联系管理员');
            }
            
            if ($res['password'] == md5($password)) {
                //登录成功
                //dump($res);
                Session::set('user', $res);
                $this->success('登录成功!', '/ypz_forum_admin/deal/mesdeal');
            } else {
                $this->error('密码不正确!');
            }
        }
        $this->error('用户名不存在, 登录失败!');
    }
    
    public function index()
    {
        return view();
    }
    
    public function detail()
    {
        return view();
    }
}
